package model

import (
	"gorm.io/gorm"
	"shop/database/mysql"
)

// 商品属性值表
type GoodsPropertyValue struct {
	gorm.Model
	PropertyId int64  `gorm:"column:property_id;type:int(11);comment:属性id" json:"property_id"`
	Name       string `gorm:"column:name;type:varchar(255)" json:"name"`
	GoodsId    int64  `gorm:"column:goods_id;type:int(11)" json:"goods_id"`
}

func (g *GoodsPropertyValue) GoodsPropertyPropertyIdList(propertyIds []int64) (goods []*GoodsPropertyValue, err error) {
	return goods, mysql.WithMysql(func(db *gorm.DB) error {
		return db.Model(g).Where("property_id in(?)", propertyIds).Find(&goods).Error
	})
}

// 通过属性值id获取商品属性值
func (g *GoodsPropertyValue) GetGoodsPropertyValueByID(ID int64) (info *GoodsPropertyValue, err error) {
	err = mysql.WithMysql(func(db *gorm.DB) error {
		return db.Model(g).Where("id = ?", ID).Find(&info).Error
	})
	return
}
